

package ro.ase.catalog.security.dao.hibernate;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import ro.ase.catalog.beans.AclObjectIdentity;
import ro.ase.catalog.dao.hibernate.GenericDAOImpl;
import ro.ase.catalog.security.dao.IAclObjectIdentityDAO;

import java.util.List;

/**
 *
 */
public class AclObjectIdentityDAOImpl extends GenericDAOImpl<AclObjectIdentity, Long>  implements IAclObjectIdentityDAO {

    /* (non-Javadoc)
     * @see IAclObjectIdentityDAO#findByObjectId(long, long)
     */
    @SuppressWarnings("unchecked")
    public AclObjectIdentity findByObjectId(long objectIdClass,
            long objectIdIdentity) {
        DetachedCriteria criteria = DetachedCriteria.forClass(AclObjectIdentity.class);
        criteria.add(Expression.eq("objectId", objectIdIdentity))
                .createCriteria("aclClass")
                .add(Expression.eq("id", objectIdClass));

        List<AclObjectIdentity> list = getHibernateTemplate().findByCriteria(criteria);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }


}
